import numpy as np
import cv2
import serial
import glob
import pickle
import threading
from queue import Queue
from assitant import *
from main import *
import time

camera = cv2.VideoCapture(0)
while True:
    _,img = camera.read()
    if cv2.waitKey(1)==13:break
    cv2.imshow('p',img)



def task1(l, p):
    for i in range(100):
        print('task1:', i)
        time.sleep(1)


def task2(a, q):
    while True:
        a = input('>>')
        if a == 'q':
            break
        print('ok')


def init_uart():
    ready = False
    path = '/dev/ttyUSB'
    usb_id = '0'
    while not ready:
        try:
            uart = serial.Serial(path + usb_id, 115200)
            uart = True
        except:
            if usb_id == '0':
                usb_id = '1'
            else:
                usb_id = '0'
            time.sleep(1000)
            if indebug:
                print('connect failed')
    return uart

if __name__ == '__main__':
    # line1 = np.array([20,20,800,800])
    # line2 = np.array([40,90,600,650])
    # line3 = merge_ls(line1,line2)
    # img = np.zeros((1000,1000,3),'uint8')
    # cv2.line(img, tuple(line1[0:2]), tuple(line1[2:4]), (255, 255, 0), 1)
    # cv2.line(img, tuple(line2[0:2]), tuple(line2[2:4]), (255, 255, 0), 1)
    # cv2.line(img, tuple(line3[0:2]), tuple(line3[2:4]), (255, 255, 255), 1)
    # cv2.imshow("t",img)
    # cv2.waitKey()
    #
    # img = cv2.imread('img4.png')
    # [ok,lines] = init_para(img)
    # if ok:
    #     for line in lines:
    #         cv2.line(img, tuple(line[0:2]), tuple(line[2:4]), (255, 255, 0), 2)
    #     point = lines_cross_points(lines)
    #     point = order_points(point)
    #     for p in point:
    #         cv2.circle(img, tuple(p), 2, [0, 0, 0],-1)
    #
    #     cv2.imshow("img2", img)
    #     cv2.waitKey()
    # print('failed')
    t = threading.Thread(target=task1, args=('1', '2'), name='task1')
    t2 = threading.Thread(target=task2, args=('1', '2'), name='task2')
    # 对已经开启的线程进行传参数（data[i],q）
    # 创建线程
    print(t)
    t.start()
    t2.start()
    while True:
        time.sleep(10)

